package com.car.carmgr.service.impl;

import com.car.carmgr.bean.Car;
import com.car.carmgr.bean.Customer;
import com.car.carmgr.bean.Rent;
import com.car.carmgr.mapper.CarMapper;
import com.car.carmgr.service.CarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public int insertCar(Car car) {
        return carMapper.insertCar(car);
    }

    @Override
    public int deleteCarById(String carId) {
        return carMapper.deleteCarById(carId);
    }

    @Override
    public int updateCar(Car car) {
        return carMapper.updateCar(car);
    }

    @Override
    public int findCarById(String carNumber) {
        return carMapper.findCarById(carNumber);
    }

    @Override
    public PageInfo<Car> findCarByWhere(String carNumber, String carType, String color, Double price, Double rentPrice, Double deposit, Integer isRenting, String description, String carImg, Date createTime, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Car> list = carMapper.findCarByWhere(carNumber, carType,color, price, rentPrice, deposit, isRenting, description,carImg,createTime);
        PageInfo<Car> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer getCountByWhere(String carNumber, String carType, String color, Double price, Double rentPrice, Double deposit, Integer isRenting, String description,String carImg, Date createTime) {
        return carMapper.getCountByWhere(carNumber, carType,color, price, rentPrice, deposit, isRenting, description,carImg,createTime);
    }

    @Override
    public int deleteSomeCar(String[] split) {
        int row = 0;
        if(split != null && split.length != 0){

            for(String userId : split){
                row += carMapper.deleteCarById(userId);
            }
        }
        return row;
    }

    @Override
    public PageInfo<Car> findALL(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Car> all = carMapper.findAll();
        return new PageInfo<Car>(all);
    }

    @Override
    public Integer getCount() {
        return carMapper.getCount();
    }
}
